import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ConfigService } from '@nestjs/config';
import { RevokeRecordInterceptor } from './revoke-record.interceptor';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { Logger } from '@nestjs/common';
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // app.useGlobalInterceptors(new FormatResponseInterceptor());
  app.useGlobalInterceptors(new RevokeRecordInterceptor());
  app.enableCors();
  const config = new DocumentBuilder()
    .setTitle('会议预约系统')
    .setDescription('api接口文档')
    .setVersion('1.0')
    .addBearerAuth({
      type: 'http',
      description: '基于jwt的认证',
    })
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api-doc', app, document);
  app.useStaticAssets('uploads', { prefix: '/uploads' });
  const configService = app.get(ConfigService);
  await app.listen(configService.get('app.port') ?? 3005);
}
bootstrap().catch((err) => {
  const logger = new Logger('Main');
  logger.error('应用启动失败', err.stack);
  process.exit(1); // 错误退出（代码1，区分正常退出）
});
